package model;

import java.util.Collection;
import java.util.Vector;

/**
 * The RectangularPartCollection class contains a collection of RectangularParts which
 * do not overlap.
 *
 */
public class RectangularPartCollection {
	
	private Collection<RectangularPart> parts;

	/**
	 * Constructor of RectangularPartCollection.
	 */
	public RectangularPartCollection(){
		this.setParts(new Vector<RectangularPart>());
	}

	public Collection<RectangularPart> getParts() {
		return parts;
	}

	public void setParts(final Collection<RectangularPart> parts) {
		this.parts = parts;
	}

	/**
	 * Adds a single {@link RectangularPart} to this {@link RectangularPartCollection}.
	 * @param newPart
	 */
	public void add(final RectangularPart newPart) {
		for(final RectangularPart part : this.getParts())
		{
			if(newPart.overlaps(part)) throw new Error("\n" + newPart.toString() + " and \n " + part.toString() + " overlap.");
		}
		this.getParts().add(newPart);
	}
	
	/**
	 * Adds each {@link RectangularPart} of the provided {@link RectangularPartCollection} into this 
	 * {@link RectangularPartCollection}.
	 * @param partCollection is the {@link RectangularPartCollection} that is be added to this
	 *  {@link RectangularPartCollection}
	 * @throws	Error if one of the {@link RectangularPart}s in the provided {@link RectangularPartCollection} overlaps with one of the
	 * 			{@link RectangularPart}s in this {@link RectangularPartCollection} .
	 */
	public void add(final RectangularPartCollection partCollection) {
		for(final RectangularPart newPart : partCollection.getParts())
		{
			for(final RectangularPart part : this.getParts())
			{
				if(newPart.overlaps(part)) throw new Error("\n" + newPart.toString() + " and \n " + part.toString() + " overlap.");
			}
		}
		this.getParts().addAll(partCollection.parts);
	}
	
	public Vector<RectangularPart> toVector() {
		return (Vector<RectangularPart>) this.parts;
	}
}
